﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication1.Class.Bean;
using System.Configuration;
using WpfApplication1.Control;
using WpfApplication1.GestionBug;

namespace WpfApplication1
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    /// 
    public partial class MainWindow : Window
    {
        
        public MainWindow()
        {
            
            
        }

        private void ValidConnection(object sender, RoutedEventArgs e)
        {

            List<SearchField> list = new List<SearchField>();
            list.Add(new SearchField("Login", this.loginInput.Text, SearchField.EGAL_A));
            list.Add(new SearchField("Password", this.passwordInput.Password, SearchField.EGAL_A));

            List<ClassPersonne> listPersonne = ClassPersonne.Search(list);

            /* Test en base afin de verifier l'existence du user */
            if (listPersonne.Count > 0)
            {
                /* Instanciation du SINGLETON */
                ClassPersonne currentUser = listPersonne.First();

                ClassCurrentUserSingleton.Instance.Id = currentUser.Id;
                ClassCurrentUserSingleton.Instance.IdProjet = currentUser.IdProjet;
                ClassCurrentUserSingleton.Instance.Login = currentUser.Login;
                ClassCurrentUserSingleton.Instance.Nom = currentUser.Nom;
                ClassCurrentUserSingleton.Instance.Prenom = currentUser.Prenom;
                ClassCurrentUserSingleton.Instance.Password = currentUser.Password;
                ClassCurrentUserSingleton.Instance.Role = currentUser.Role;

                BugWindow bugWindow = new BugWindow();
                bugWindow.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Utilisateur non reconnu");
            }
        }
    }
}
